package com.fyzk.activity.zhifu.zc;

import android.content.Context;
import android.graphics.Typeface;
import android.text.SpannableString;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.CheckBox;
import android.widget.TextView;

import com.fyzk.bean.ZCGameQueueItem;
import com.tyjc.lottery.R;
import com.fyzk.utils.TextStyleUtil;

import java.util.List;

public class ZhiFu_JQC_Adapter extends ZhiFu_ZC_Adapter{


	public ZhiFu_JQC_Adapter(Context context, List<ZCGameQueueItem> infors) {
		super(context, infors);
	}

	@Override
	public View getView(final int position, View convertView, ViewGroup parent) {
		// TODO Auto-generated method stub
		final ZCGameQueueItem data = infors.get(position);
		final ViewHolder holder;
		if (convertView == null) {
			holder = new ViewHolder();
			convertView = LayoutInflater.from(context).inflate(R.layout.adapter_jqc_pay, null);

			holder.num_tv =  (TextView) convertView.findViewById(R.id.jqc_pay_item_num);
			holder.home_tv =  (TextView) convertView.findViewById(R.id.zc_jqc_home);
			holder.away_tv = (TextView) convertView.findViewById(R.id.zc_jqc_away);
			holder.sheng_tv = (TextView) convertView.findViewById(R.id.zc_jqc_pl_sheng);
			holder.ping_tv = (TextView) convertView.findViewById(R.id.zc_jqc_pl_ping);
			holder.fu_tv = (TextView) convertView.findViewById(R.id.zc_jqc_pl_fu);
			holder.home_qiu0_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_home_qiu0);
			holder.home_qiu1_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_home_qiu1);
			holder.home_qiu2_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_home_qiu2);
			holder.home_qiu3_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_home_qiu3);
			holder.away_qiu0_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_away_qiu0);
			holder.away_qiu1_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_away_qiu1);
			holder.away_qiu2_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_away_qiu2);
			holder.away_qiu3_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_away_qiu3);
			holder.quanBao_check = (CheckBox) convertView.findViewById(R.id.zc_jqc_quanbao);

			convertView.setTag(holder);
		}else{
			holder = (ViewHolder) convertView.getTag();
		}

		holder.num_tv.setText(""+(position+1));

		holder.home_tv.setText(data.getHomeTeam());
		holder.away_tv.setText(data.getAwayTeam());
		holder.sheng_tv.setText("胜"+data.getVs_3());
		holder.ping_tv.setText("平"+data.getVs_1());
		holder.fu_tv.setText("负"+data.getVs_0());

		holder.home_qiu0_check.setChecked(data.isCheckQiu0_home);
		holder.home_qiu1_check.setChecked(data.isCheckQiu1_home);
		holder.home_qiu2_check.setChecked(data.isCheckQiu2_home);
		holder.home_qiu3_check.setChecked(data.isCheckQiu3_home);
		holder.away_qiu0_check.setChecked(data.isCheckQiu0_away);
		holder.away_qiu1_check.setChecked(data.isCheckQiu1_away);
		holder.away_qiu2_check.setChecked(data.isCheckQiu2_away);
		holder.away_qiu3_check.setChecked(data.isCheckQiu3_away);
		holder.quanBao_check.setChecked(data.isCheckQiu_all);



		holder.home_qiu0_check.setText(setTextStyle("0"));
		holder.home_qiu1_check.setText(setTextStyle("1"));
		holder.home_qiu2_check.setText(setTextStyle("2"));
		holder.home_qiu3_check.setText(setTextStyle("3+"));
		holder.away_qiu0_check.setText(setTextStyle("0"));
		holder.away_qiu1_check.setText(setTextStyle("1"));
		holder.away_qiu2_check.setText(setTextStyle("2"));
		holder.away_qiu3_check.setText(setTextStyle("3+"));

		holder.home_qiu0_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu0_home = ! data.isCheckQiu0_home;
				if (data.isCheckQiu0_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.home_qiu1_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu1_home = ! data.isCheckQiu1_home;
				if (data.isCheckQiu1_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.home_qiu2_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu2_home = ! data.isCheckQiu2_home;
				if (data.isCheckQiu2_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}
				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});


		holder.home_qiu3_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu3_home = ! data.isCheckQiu3_home;
				if (data.isCheckQiu3_home) {
					data.ban_clickNum++;
				}else{
					data.ban_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.away_qiu0_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu0_away = ! data.isCheckQiu0_away;
				if (data.isCheckQiu0_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.away_qiu1_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu1_away = ! data.isCheckQiu1_away;
				if (data.isCheckQiu1_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.away_qiu2_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu2_away = ! data.isCheckQiu2_away;
				if (data.isCheckQiu2_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});


		holder.away_qiu3_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu3_away = ! data.isCheckQiu3_away;
				if (data.isCheckQiu3_away) {
					data.quan_clickNum++;
				}else{
					data.quan_clickNum--;
				}

				if (data.ban_clickNum == 4 && data.quan_clickNum == 4) {
					data.isCheckQiu_all = true;
				}else{
					data.isCheckQiu_all = false;
				}
				holder.quanBao_check.setChecked(data.isCheckQiu_all);
				tongJi();
			}
		});

		holder.quanBao_check.setOnClickListener(new View.OnClickListener() {

			@Override
			public void onClick(View v) {
				// TODO Auto-generated method stub
				data.isCheckQiu_all = ! data.isCheckQiu_all;
				if (data.isCheckQiu_all) {
					data.ban_clickNum = 4;
					data.quan_clickNum = 4;
				}else{
					data.ban_clickNum = 0;
					data.quan_clickNum = 0;
				}
				data.isCheckQiu0_home = data.isCheckQiu_all;
				data.isCheckQiu1_home = data.isCheckQiu_all;
				data.isCheckQiu2_home = data.isCheckQiu_all;
				data.isCheckQiu3_home = data.isCheckQiu_all;
				data.isCheckQiu0_away = data.isCheckQiu_all;
				data.isCheckQiu1_away = data.isCheckQiu_all;
				data.isCheckQiu2_away = data.isCheckQiu_all;
				data.isCheckQiu3_away = data.isCheckQiu_all;

				holder.home_qiu0_check.setChecked(data.isCheckQiu0_home);
				holder.home_qiu1_check.setChecked(data.isCheckQiu1_home);
				holder.home_qiu2_check.setChecked(data.isCheckQiu2_home);
				holder.home_qiu3_check.setChecked(data.isCheckQiu3_home);
				holder.away_qiu0_check.setChecked(data.isCheckQiu0_away);
				holder.away_qiu1_check.setChecked(data.isCheckQiu1_away);
				holder.away_qiu2_check.setChecked(data.isCheckQiu2_away);
				holder.away_qiu3_check.setChecked(data.isCheckQiu3_away);
				tongJi();
			}
		});

//		if (position == jcInfors.size()) {
//			holder.bg_center.setVisibility(View.GONE);
//			holder.bg_top.setVisibility(View.GONE);
//		} else {
//			Globle.setHW(holder.bg_top, 1080, 11, context);
//			ZCGameQueueItem info = jcInfors.get(position);
//			holder.fangshi.setText("[" + ConstantsDJ.wcode(info.wcodeID) + "]");
//			holder.tv_betNum.setText(Html.fromHtml(info.showZhuMa));
//			holder.zhu.setText(info.zhuShu + "注,");
//			holder.money.setText("共 " + info.zhuShu * 2 + " 米");
//			holder.bg_center.setOnClickListener(new OnClickListener() {
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickChange(position);
//					}
//				}
//			});
//			holder.delete.setOnClickListener(new OnClickListener() {
//
//				@Override
//				public void onClick(View v) {
//					// TODO Auto-generated method stub
//					if (listener != null) {
//						listener.onClickDelete(position);
//					}
//				}
//			});
//		}
		
		
		
		return convertView;
	}

	protected void tongJi(){
		if (listener != null) {
			listener.onClickBall();
		}
	}

	private SpannableString setTextStyle(String text){
		SpannableString spanString = TextStyleUtil.fontSizeSpan(new SpannableString(text), 18);
		spanString = TextStyleUtil.styleSpan(spanString, Typeface.BOLD_ITALIC);
		return spanString;
	}

	class ViewHolder {
		TextView num_tv;
		TextView home_tv;
		TextView away_tv;
		TextView sheng_tv;
		TextView ping_tv;
		TextView fu_tv;
		CheckBox home_qiu0_check;
		CheckBox home_qiu1_check;
		CheckBox home_qiu2_check;
		CheckBox home_qiu3_check;
		CheckBox away_qiu0_check;
		CheckBox away_qiu1_check;
		CheckBox away_qiu2_check;
		CheckBox away_qiu3_check;
		CheckBox quanBao_check;
	}

}
